﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using WalkingTec.Mvvm.Core;
using System.Text.Json.Serialization;
using nERP.Model;
using nERP.Model.Po;
using nERP.Model.Bas;
using nERP.Model.Wms;

namespace nERP.Model.Po
{
    /// <summary>
    /// 采购退货
    /// </summary>
	[Table("BuyReturn")]
    [SoftKey(nameof(BuyReturn.BuyReturnCode))]
    [Display(Name = "_Model.BuyReturn")]
    public class BuyReturn : BasePoco, IPersistPoco, ITenant, IWorkflow
    {
        [Display(Name = "_Model._BuyReturn._BuyReturnCode")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("退货单号")]
        [Required(ErrorMessage = "Validate.{0}required")]
        [CanNotEdit]
        public string BuyReturnCode { get; set; }
        [Display(Name = "_Model._BuyReturn._BuyInWarehouse")]
        [Comment("采购入库")]
        [NotMapped]
        public BuyInWarehouse BuyInWarehouse { get; set; }
        [Display(Name = "_Model._BuyReturn._BuyInWarehouse")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Required(ErrorMessage = "Validate.{0}required")]
        [Comment("采购入库")]
        public string BuyInWarehouseId { get; set; }
        [Display(Name = "_Model._BuyReturn._Buy")]
        [Comment("采购单号")]
        [NotMapped]
        public Buy Buy { get; set; }
        [Display(Name = "_Model._BuyReturn._Buy")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Required(ErrorMessage = "Validate.{0}required")]
        [Comment("采购单号")]
        public string BuyId { get; set; }
        [Display(Name = "_Model._BuyReturn._Supplier")]
        [Comment("供应商")]
        [NotMapped]
        public Supplier Supplier { get; set; }
        [Display(Name = "_Model._BuyReturn._Supplier")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("供应商")]
        public string SupplierId { get; set; }
        [Display(Name = "_Model._BuyReturn._InvoicesDate")]
        [Comment("单据日期")]
        public DateTime? InvoicesDate { get; set; }
        [Display(Name = "_Model._BuyReturn._MakeUser")]
        [Comment("制单人")]
        [NotMapped]
        public FrameworkUser MakeUser { get; set; }
        [Display(Name = "_Model._BuyReturn._MakeUser")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("制单人")]
        public string MakeUserId { get; set; }
        [Display(Name = "_Model._BuyReturn._Status")]
        [Comment("单据状态")]
        public StatusTypeEnum? Status { get; set; }
        [Display(Name = "_Model._BuyReturn._InvoicesImage")]
        [Comment("单据附件")]
        public List<BuyReturnInvoicesImage> InvoicesImage { get; set; }
        [Display(Name = "_Model._BuyReturn._TotalPrice")]
        [Comment("总金额")]
        public decimal? TotalPrice { get; set; }
        [Display(Name = "_Model._BuyReturn._TotalPrice1")]
        [Comment("已结金额")]
        public decimal? TotalPrice1 { get; set; }
        [Display(Name = "_Model._BuyReturn._TotalPrice2")]
        [Comment("未结金额")]
        public decimal? TotalPrice2 { get; set; }
        [Display(Name = "_Model._BuyReturn._Remark")]
        [StringLength(256, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("备注")]
        public string Remark { get; set; }
        [Display(Name = "_Model._BuyReturnDetail._BuyReturn")]
        [InverseProperty("BuyReturn")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Po.BuyReturnDetail.BuyReturnId))]
        public List<BuyReturnDetail> BuyReturnDetail_BuyReturn { get; set; }
        [Display(Name = "_Model._BuyReturnOutWarehouse._BuyReturn")]
        [InverseProperty("BuyReturn")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Wms.BuyReturnOutWarehouse.BuyReturnId))]
        public List<BuyReturnOutWarehouse> BuyReturnOutWarehouse_BuyReturn { get; set; }
        [Display(Name = "_Model._BuyReturnOutWarehouseDetail._BuyReturn")]
        [InverseProperty("BuyReturn")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Wms.BuyReturnOutWarehouseDetail.BuyReturnId))]
        public List<BuyReturnOutWarehouseDetail> BuyReturnOutWarehouseDetail_BuyReturn { get; set; }
        [Display(Name = "_Model._BuyReturn._IsValid")]
        [Comment("是否有效")]
        [Required(ErrorMessage = "Validate.{0}required")]
        public bool IsValid { get; set; } = true;
        [StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
        public string TenantCode { get; set; }

    }
    public class BuyReturnInvoicesImage : TopBasePoco, ISubFile
    {
        public Guid BuyReturnId { get; set; }
        public BuyReturn BuyReturn { get; set; }
        public Guid FileId { get; set; }
        public FileAttachment File { get; set; }
        public int Order { get; set; }
    }

}
